package com.yy.strategy;

import com.yy.constant.AuthConstant;
import com.yy.strategy.impl.MemberLoginStrategy;
import com.yy.strategy.impl.SysUserLoginStrategy;
import org.apache.ibatis.logging.Log;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 描述
 * 作者 雷哥
 */
@Component
//public class LoginStrategyFactory implements ApplicationContextInitializer {
public class LoginStrategyFactory{

    /**
     * 获取IOC容器中所有实现了LoginStrategy的对象
     * key就是对象在IOC容器里面的名称
     */
    @Autowired
    private Map<String,LoginStrategy> loginStrategyMap=new HashMap<>();

    /**
     * 根据登录类型获取登录策略
     */
    public LoginStrategy getInstance(String loginType){
        return loginStrategyMap.get(loginType);
    }

//    @Override
//    public void initialize(ConfigurableApplicationContext applicationContext) {
//        MemberLoginStrategy memberLogin = (MemberLoginStrategy) applicationContext.getBean(AuthConstant.MEMBER_LOGIN);
//        SysUserLoginStrategy sysLogin = (SysUserLoginStrategy) applicationContext.getBean(AuthConstant.SYS_USER_LOGIN);
//
//        this.loginStrategyMap.put(AuthConstant.MEMBER_LOGIN,memberLogin);
//        this.loginStrategyMap.put(AuthConstant.SYS_USER_LOGIN,sysLogin);
//
//    }
}
